﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess;
namespace SQT.tracnghiem.Ajax.ASP.Class
{
    public partial class edit_class_model : System.Web.UI.Page
    {
        public string open = "", close = "";
        public bool mon = false, tue = false, wed = false, thu = false, fri = false, sat = false;
        public string morning1="",morning2="",afternoon1="",afternoon2="",evening1="",evening2="";
        protected void Page_Load(object sender, EventArgs e)
        {
            int id = int.Parse(Request.QueryString["id"]);
            var get_cls = new TblClassController().FetchAll().Where(x => x.Id == id).Single();
            if (get_cls.OpenDate != null)
            {
                open = DateTime.Parse(get_cls.OpenDate.ToString()).Year + "-";
                if (DateTime.Parse(get_cls.OpenDate.ToString()).Month < 10)
                    open += "0" + DateTime.Parse(get_cls.OpenDate.ToString()).Month;
                else
                    open += DateTime.Parse(get_cls.OpenDate.ToString()).Month;
                open += "-";
                if (DateTime.Parse(get_cls.OpenDate.ToString()).Day < 10)
                    open += "0" + DateTime.Parse(get_cls.OpenDate.ToString()).Day;
                else
                    open += DateTime.Parse(get_cls.OpenDate.ToString()).Day;
            }

            if (get_cls.CloseDate != null)
            {
                close = DateTime.Parse(get_cls.CloseDate.ToString()).Year + "-";
                if (DateTime.Parse(get_cls.CloseDate.ToString()).Month < 10)
                    close += "0" + DateTime.Parse(get_cls.CloseDate.ToString()).Month;
                else
                    close += DateTime.Parse(get_cls.CloseDate.ToString()).Month;
                close += "-";
                if (DateTime.Parse(get_cls.CloseDate.ToString()).Day < 10)
                    close += "0" + DateTime.Parse(get_cls.CloseDate.ToString()).Day;
                else
                    close += DateTime.Parse(get_cls.CloseDate.ToString()).Day;
            }

            string temp = get_cls.Schedule;
            string[] split = new string[7];
            split = temp.Split(',');
            for (int i = 0; i < temp.Split(',').Length - 1; i++)
            {
                if (split[i] == "1")
                    mon = true;
                if (split[i] == "2")
                    tue = true;
                if (split[i] == "3")
                    wed = true;
                if (split[i] == "4")
                    thu = true;
                if (split[i] == "5")
                    fri = true;
                if (split[i] == "6")
                    sat = true;
            }

            temp = get_cls.TimeStudy;

            split = temp.Split(',');
            string[] split2 = new string[2];
            if (split[0] != "")
            {
                split2 = split[0].Split('_');
                morning1 = split2[0];
                morning2 = split2[1];
            }

            if (split[1] != "")
            {
                split2 = split[1].Split('_');
                afternoon1 = split2[0];
                afternoon2 = split2[1];
            }

            if (split[2] != "")
            {
                split2 = split[2].Split('_');
                evening1 = split2[0];
                evening2 = split2[1];
            }

            DateTime time = new DateTime();
            if (morning1!="")
            {
                time = DateTime.Parse(morning1);
                morning1 = "";
                if (time.Hour < 10)
                    morning1 += "0" + time.Hour;
                else
                    morning1 += time.Hour;
                morning1 += ":";

                if (time.Minute < 10)
                    morning1 += "0" + time.Minute;
                else
                    morning1 += time.Minute;
            }
            if (morning2 != "")
            {
                time = DateTime.Parse(morning2);
                morning2 = "";
                if (time.Hour < 10)
                    morning2 += "0" + time.Hour;
                else
                    morning2 += time.Hour;
                morning2 += ":";

                if (time.Minute < 10)
                    morning2 += "0" + time.Minute;
                else
                    morning2 += time.Minute;
            }
            if (afternoon1 != "")
            {
                time = DateTime.Parse(afternoon1);
                afternoon1 = "";
                if (time.Hour < 10)
                    afternoon1 += "0" + time.Hour;
                else
                    afternoon1 += time.Hour;
                afternoon1 += ":";

                if (time.Minute < 10)
                    afternoon1 += "0" + time.Minute;
                else
                    afternoon1 += time.Minute;
            }
            if (afternoon2 != "")
            {
                time = DateTime.Parse(afternoon2);
                afternoon2 = "";
                if (time.Hour < 10)
                    afternoon2 += "0" + time.Hour;
                else
                    afternoon2 += time.Hour;
                afternoon2 += ":";

                if (time.Minute < 10)
                    afternoon2 += "0" + time.Minute;
                else
                    afternoon2 += time.Minute;
            }
            if (evening1 != "")
            {
                time = DateTime.Parse(evening1);
                evening1 = "";
                if (time.Hour < 10)
                    evening1 += "0" + time.Hour;
                else
                    evening1 += time.Hour;
                evening1 += ":";

                if (time.Minute < 10)
                    evening1 += "0" + time.Minute;
                else
                    evening1 += time.Minute;
            }
            if(evening2!="")
            {
            time = DateTime.Parse(evening2);
            evening2 = "";
            if (time.Hour < 10)
                evening2 += "0" + time.Hour;
            else
                evening2 += time.Hour;
            evening2 += ":";

            if (time.Minute < 10)
                evening2 += "0" + time.Minute;
            else
                evening2 += time.Minute;
                }
        }
    }
}